package com.xique.door.controller;


import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.BuildHouseUser;
import com.xique.door.biz.service.IHouseUserBizService;
import com.xique.door.service.IBuildHouseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 房屋用户中间表Controller
 *
 * @author caogq
 * @date 2021-09-09
 */
@Controller
@RequestMapping("/build/houseUser")
public class BuildHouseUserController extends BaseController {

    @Autowired
    private IBuildHouseUserService buildHouseUserService;

    @Autowired
    private IHouseUserBizService houseUserBizService;

    /**
     * 查询房屋用户中间表列表
     */
    @PreAuthorize(hasPermi = "build:houseUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BuildHouseUser buildHouseUser) {
        startPage();
        List<BuildHouseUser> list = buildHouseUserService.selectBuildHouseUserList(buildHouseUser);
        return getDataTable(list);
    }

    /**
     * 导出房屋用户中间表列表
     */
    @PreAuthorize(hasPermi = "build:houseUser:export")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,BuildHouseUser buildHouseUser) throws IOException {
        List<BuildHouseUser> list = buildHouseUserService.selectBuildHouseUserList(buildHouseUser);
        ExcelUtil<BuildHouseUser> util = new ExcelUtil<BuildHouseUser>(BuildHouseUser.class);
         util.exportExcel(response,list, "houseUser");
    }

    /**
     * 新增保存房屋用户中间表
     */
    @PreAuthorize(hasPermi = "build:houseUser:add")
    @Log(title = "房屋用户中间表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BuildHouseUser buildHouseUser) {
        return toAjax(buildHouseUserService.insertBuildHouseUser(buildHouseUser));
    }

    /**
     * 修改保存房屋用户中间表
     */
    @PreAuthorize(hasPermi = "build:houseUser:edit")
    @Log(title = "房屋用户中间表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BuildHouseUser buildHouseUser) {
        return toAjax(buildHouseUserService.updateBuildHouseUser(buildHouseUser));
    }

    /**
     * 删除房屋用户中间表
     */
    @PreAuthorize(hasPermi = "build:houseUser:remove")
    @Log(title = "房屋用户中间表", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(buildHouseUserService.deleteBuildHouseUserByIds(ids));
    }

    @GetMapping("/houseUserList")
    @ResponseBody
    public AjaxResult houseUserList(Long houseId) {
        return houseUserBizService.getHouseUserList(houseId);
    }
}
